# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/10/25 16:31

import pandas as pd
from datetime import datetime
from Common.business_common_tool import BusinessCommonTools
from Common.get_sql_object import GetSqlObject
from Common.tool import Tool
from Common.dingtalk import Ding
from datetime import timedelta
from Common.do_mysql import DoMysql
import os

# 获取当前日期
now = datetime.now()
end_year, end_month = now.year, now.month
# 生成从2024年11月到当前月份的列表
months_list = Tool().generate_months(2025, 2, end_year, end_month)
months_list.reverse() #反转列表

# 获取本周日期列表
data_list = Tool().get_current_week()



mysql_source = GetSqlObject.get_instance("PRO")
#组装成excel数据,放到字典中去
df = {}
for i in months_list:
    query_waybill_list = BusinessCommonTools().get_query_waybill_list_xiaoshou('PRO',i, mysql_source)
    df[i]= pd.DataFrame(query_waybill_list)

# 已审核通过车辆,已审核通过货主,新增加线路物流企业
# consignor_list,logistics_line,query_driver_line=BusinessCommonTools().get_consignor20241230('PRO',mysql_source)
# #组装成excel数据
# df1 = pd.DataFrame(consignor_list)
# df2 = pd.DataFrame(logistics_line)
# df3 = pd.DataFrame(query_driver_line)

# 指定要创建的文件夹路径
# 创建文件夹，如果文件夹不存在则创建，如果存在则不创建
os.makedirs(f'New/{months_list[0]}', exist_ok=True)

# 指定要导出的Excel文件名
excel_file = f'New/{months_list[0]}/订单{now.date()}.xlsx' # 生产环境文件存放地址
#excel_file = f'File/{months_list[0]}/运单详情{now.date()}.xlsx'
excel_file_path = f'http://47.116.122.206/{excel_file}'

# 使用ExcelWriter对象
with pd.ExcelWriter(excel_file, engine='xlsxwriter') as writer:
    # df1.to_excel(writer, sheet_name=f'货主', index=False)
    # df2.to_excel(writer, sheet_name=f'专线', index=False)
    # df3.to_excel(writer, sheet_name=f'司机', index=False)
    for i in months_list:
        df[i].to_excel(writer, sheet_name=i, index=False)
        # worksheet = writer.sheets[i]
        # worksheet.set_column('G:G', None, None, {'hidden': True})
        # worksheet.set_column('H:H', None, None, {'hidden': True})
        # worksheet.set_column('I:I', None, None, {'hidden': True})
        # worksheet.set_column('J:J', None, None, {'hidden': True})
        # worksheet.set_column('K:K', None, None, {'hidden': True})
        # worksheet.set_column('L:L', None, None, {'hidden': True})
        # worksheet.set_column('M:M', None, None, {'hidden': True})
        # worksheet.set_column('N:N', None, None, {'hidden': True})
        # worksheet.set_column('O:O', None, None, {'hidden': True})
        # worksheet.set_column('P:P', None, None, {'hidden': True})







result_string = f"{now.date()}统计:\n"
result_string += f"(点击下载)：{excel_file_path}\n"

print(result_string)

Ding().ding_hami_xiaoshou(result_string)





